<?php
	$url_site = 'http://localhost';
	$dossier_site = 'C:\wamp\www';
	
	// Connexion à  la base de données
	try {
		$db_config['HOST']	= 'localhost';
		$db_config['DB_NAME']	= 'teamfrlb';
		$db_config['USER']	= 'root';
		$db_config['PASSWORD']	= '';
		$strConnection = 'mysql:host='. $db_config['HOST'] .';dbname='. $db_config['DB_NAME']; //Ligne 1
		$arrExtraParam= array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"); //Ligne 2
		$bdd = new PDO($strConnection, $db_config['USER'], $db_config['PASSWORD'], $arrExtraParam); //Ligne 3; Instancie la connexion
		$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);//Ligne 4
	}
	catch(PDOException $e) {
		$msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
		die($msg);
	}
	
	header ('Content-type:text/html; charset=utf-8');
	
	session_start();
	
	include_once('fonction.php');
	
	if(!isset($_COOKIE['visite'])){
		$bdd->exec('UPDATE planetside2_compteur SET visite = visite + 1 WHERE id = \'1\' ');
		setcookie('visite', '0', 0, null, null, false, true);// le cookie expirera à  la fin de la session (lorsque le navigateur sera fermé).
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
	<head>
		<title> Team FRLB </title>
		<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
		<meta name="description" content="Site de la team FrLB" />
		<meta name="keywords" content="team,frlb,planetside2,planetside2,cobalt" />
		<link href="<?php echo $url_site; ?>/theme/style.css" rel="stylesheet" /> 
		<link href="<?php echo $url_site; ?>/theme/images/logo.png" rel="icon" type="image/png" />
		<link href="<?php echo $url_site; ?>/theme/images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
		
		<link href="<?php echo $url_site; ?>/theme/editeur/style.css" rel="stylesheet" />
		<script type="text/javascript" src="<?php echo $url_site; ?>/editeur/editeur.js"></script>
	</head>
	<body>
		<div id="contenu">
			<div id="header">
				<div id="info-header"><?php
					$reponse = $bdd->query('SELECT * FROM planetside2_news ORDER BY id DESC LIMIT 0, 1');
					$donnees = $reponse->fetch();
					
					echo "<u>".$donnees['titre']."</u> (". date('d/m/y', strtotime($donnees['timestamp'])).")<br />"; 
					// On enlève les éventuels antislash PUIS on crée les entrées en HTML (<br />)
					$contenu = nl2br(stripslashes($donnees['contenu']));
					$nbmots = 200;

					if(strlen($contenu) > $nbmots) {
					   $contenu = substr($contenu, 0, $nbmots);
					   $espace = strrpos($contenu, " ");
					   $contenu = substr($contenu, 0, $espace)."";

					   echo $contenu . ' (...) <a href="' . $url_site . '/information.php?id=' . $donnees['id'] . '">[Lire la suite]</a>';
					}
					else {
						echo $contenu;
					}
					$reponse->closeCursor();
				?></div>
				<ul id="menu">				
						<li id="menu-h1"><?php
								if(isset($_SESSION['pseudo'])) {
									echo '<a href="' . $url_site . '/#compte.php">Mon Compte#</a>';
								}
								else {
									echo '<a href="' . $url_site . '/inscription.php">Inscription</a>';
								}
						?></li>
						<li id="menu-h2"><a href="<?php echo $url_site; ?>/index.php">Accueil</a></li>
						<li id="menu-h3"><a href="#">Evénement</a>
							<ul>
								<li><a href="<?php echo $url_site; ?>/evenement_unite.php">De l'unité</a></li>
								<li><a href="<?php echo $url_site; ?>/evenement.php?event=halloween">Halloween</a></li>
								<li><a href="<?php echo $url_site; ?>/evenement.php?event=noel">Noël</a></li>
								<li><li><a href="<?php echo $url_site; ?>/evenement.php?event=paques">Pâques</a></li>
								<li><li><a href="<?php echo $url_site; ?>/evenement.php?event=ete">Eté</a></li>
							</ul>
						</li>
						<li id="menu-h4"><a href="#">Statistiques#</a>
							<ul>
								<li><a href="#">Classement#</a></li>
								<li><a href="#">Armes#</a></li>
								<li><a href="#">Ratio#</a></li>
								<li><a href="#">Véhicule#</a></li>
							</ul>
						</li>
						<li id="menu-h5"><a href="#">Aide</a>
							<ul>
								<li><a href="http://frlb.forumactif.org/forum" target="blank">Forum</a></li>
								<li><a href="http://frlb.forumactif.org/chatbox/index.forum" target="blank">Tchat</a></li>
								<li><a href="http://steamcommunity.com/groups/frlbps2" target="blank">Steam</a></li>
								<li><a href="<?php echo $url_site; ?>/guide.php">Guide</a></li>
							</ul>
						</li>
						<li id="menu-h6"><a href="<?php echo $url_site; ?>/unite.php">L'unité</a>
							<ul>
								<li><a href="#">Capture d'écran#</a></li>
							</ul>
						</li>
						<li id="menu-h7"><a href="#">Information</a>
							<ul>
								<li><a href="<?php echo $url_site; ?>/serveur.php">Statut du serveur</a></li>
								<li><a href="<?php echo $url_site; ?>/membre_en_ligne.php">Connecté(s)</a></li>
								<li><a href="<?php echo $url_site; ?>/perso.php">Personnage</a></li>
								<li><a href="<?php echo $url_site; ?>/twitch.php">Live</a></li>
							</ul>
						</li>
						<li id="menu-h8"><?php
							if(isset($_SESSION['pseudo'])) {
								echo '<a href="' . $url_site . '/deconnexion.php">Déconnexion</a>';
							}
							else {
								echo '<a href="' . $url_site . '/connexion.php">Connexion</a>';
							}
						?></li>
					</ul>
				
				
				
				<div id="sous_menu"><?php
				if(!empty($_SESSION['pseudo'])) {
					echo saluerheure(date("H")).' <strong>' . $_SESSION['pseudo'] . '</strong>';
				}
				else {
					echo 'Vous n\'êtes pas connecté.';
				}
		?></div>
			</div>
			<div id="milieu">
			<?php
			if(getcwd() == $dossier_site . '\admin' && !empty($_SESSION['pseudo'])) {
				$reponse = $bdd->prepare('SELECT staff FROM planetside2_membre WHERE pseudo = :pseudo AND staff = "admin"');
				$reponse->execute(array('pseudo' => $_SESSION['pseudo']));
				$resultat = $reponse->fetch();
				$reponse->closeCursor();
				if ($resultat) {
					$acces_admin = 'Autorisé';
				?>
					<div id="nav-menu">
						<div class="tete-menu"><h1>Administration</h1></div>
						<ul class="corp-menu">
							<li><a href="<?php echo $url_site; ?>/admin/admin_contact.php">Administration des contacts</a></li>
							<li><a href="<?php echo $url_site; ?>/admin/confirm_membre.php">confirmer un membre</a></li>
							<li><a href="<?php echo $url_site; ?>/admin/creer_evenement.php">Créer un évènement</a></li>
						</ul>
						<div class="pied-menu"></div>
					</div>
				<?php
				}
			}
			?>